#define     DS1305_CS_BIT        PB5            
#define     DS1305_CS_PORT       PORTB      
#define     DS1305_CS_PORT_DIR   DDRB   

void DS1305_init(void)
{
DS1305_CS_PORT_DIR|= 1<<DS1305_CS_BIT;                             // set DateFlash CS line as output
DS1305_CS_PORT&= ~(1<<DS1305_CS_BIT);                              // disable CS line 
}


unsigned char DS1305_read_byte(unsigned char address)
{
    DS1305_CS_PORT |=  1<<DS1305_CS_BIT;
    SPDR = address;
    while (!SPSR);
    SPDR = 0;
    while (!SPSR);
    DS1305_CS_PORT &=  ~(1<<DS1305_CS_BIT);
    return (SPDR);
}   

void DS1305_write_byte(unsigned char address,unsigned char data)
{
    DS1305_CS_PORT |=  1<<DS1305_CS_BIT;
    SPDR = address;
    while (!SPSR);
    SPDR = data;
    while (!SPSR);
    DS1305_CS_PORT &=  ~(1<<DS1305_CS_BIT);
}  
   
